<?php namespace Admin\Controller; 

use Hdphp\Controller\Controller;

//测试控制器
class AttrController extends CommonController{
	private $attrModel;
	//构造函数
	public function __init()
	{
		parent::__init();
		$this->attrModel = new \Common\Model\Attr;
	}
	
//	首页显示
	public function index(){
//		获得要展示的type_tid
		$tid = Q('get.tid',0,'intval');
		$typeModel = new \Common\Model\Type;
		$tname = $typeModel->where("tid = {$tid}")->pluck('tname');
		View::with('tname',$tname);
//		查找该类型的属性
		$attrData = $this->attrModel->where("type_tid = {$tid}")->get();
//		分配数据
		View::with('attrData',$attrData);
//		分配数据
		View::with('tid',$tid);
		View::make();
	}
	
//	添加类型
	public function add(){
		$tid = Q('post.type_tid',0,'intval');
//		获得要添加
		if(IS_POST){
			if(!$this->attrModel->stroe()) View::error($this->attrModel->getError());
			View::success('添加成功',U('Attr/index',array('tid'=>$tid)));
		}
		View::make();
	}
//	类型编辑
	public function edit(){
		$atid = Q('get.atid',0,'intval');
		$tid = Q('get.tid',0,'intval');
		if(IS_POST){
			if(!$this->attrModel->edit()) View::error($this->attrModel->getError());
			View::success('修改成功',U('Attr/index',array('tid'=>$tid)));
		}
		$attrData = $this->attrModel->where("atid = {$atid}")->find();
		View::with('attrData',$attrData);
		View::make();
	}
	
//	删除类型
	public function del(){
		$atid = Q('get.atid',0,'intval');
		$tid = Q('get.tid',0,'intval');
		$this->attrModel->where("atid = {$atid}")->delete();
		View::success('删除成功',U('Attr/index',array('tid'=>$tid)));
	}
	
	
	
}
